package com.qfedu.defect.task.contronller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.common.R;
import com.qfedu.defect.task.dto.DefectTaskDto;
import com.qfedu.defect.task.pojo.DefectTask;
import com.qfedu.defect.task.service.DefectTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/defectTask")
public class DefectTaskController {

    @Autowired
    private DefectTaskService defectTaskService;

    @GetMapping
    public R<Page<DefectTask>> getDefectTasks(DefectTaskDto taskDto){
        return R.ok(defectTaskService.getDefectTasks(taskDto));
    }

    @PostMapping
    public R<Boolean> addDefectTask(@RequestBody DefectTask defectTask){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(defectTaskService.save(defectTask));
    }

    @PutMapping
    public R<Boolean> updateDefectTask(@RequestBody DefectTask defectTask){
//        defectTask.setState(StringUtils.hasLength(defectTask.getDefectUser()) ? 1 : 0);
        return R.ok(defectTaskService.updateById(defectTask));
    }

    @DeleteMapping("/{id}")
    public R<Boolean> deleteDefectTask(@PathVariable("id") Long id){
        return R.ok(defectTaskService.removeById(id));
    }
}
